package com.fishsoup.fishweb.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fishsoup.entity.http.ResponseResult;
import com.fishsoup.fishweb.domain.Footstep;
import com.fishsoup.fishweb.enums.ArtworkTypeEnum;
import com.fishsoup.fishweb.service.FootstepService;
import com.fishsoup.util.DateUtils;
import lombok.RequiredArgsConstructor;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;

import java.time.Duration;

@RestController
@RequiredArgsConstructor
@RequestMapping("/footstep")
public class FootstepController {

    private final FootstepService footstepService;

    @GetMapping("/page/{artworkType}/{pageNum}/{pageSize}")
    public IPage<Footstep> pageFootsteps(@PathVariable("artworkType") String artworkType,
        @PathVariable("pageNum") int pageNum, @PathVariable("pageSize") int pageSize) {
        return footstepService.pageFootsteps(ArtworkTypeEnum.valueOf(artworkType), pageNum, pageSize);
    }

    @PostMapping()
    public ResponseResult saveFootstep(@RequestBody Footstep footstep) {
        footstepService.saveFootstep(footstep);
        return ResponseResult.success();
    }

    /**
     * 删除1天前的足迹
     * @return 执行结果
     */
    @DeleteMapping()
    @Scheduled(cron = "0 0 0 * * *")
    @SchedulerLock(name = "cleanFootstepHistory")
    public void removeFootstep() {
        footstepService.deleteFootstepHis();
    }
}
